#include <cstdio>
#include <algorithm>
#include <cstring>
typedef long long ll;
using namespace std;
const int N=7;
const ll MOD=2147493647;
struct Mat{
    ll m[N][N];
};
Mat operator * (Mat a,Mat b){
    Mat t;
    memset(t.m,0,sizeof(t.m));
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            if(a.m[i][k]==0){
                continue;
            }
            for(int j=0;j<N;j++){
                if(b.m[k][j]==0){
                    continue;
                }
                t.m[i][j]=(t.m[i][j]+(a.m[i][k]%MOD)*(b.m[k][j]%MOD))%MOD;
            }
        }
    }
    return t;
}
Mat operator ^ (Mat a,int n){
    Mat t;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            t.m[i][j]=i==j?1:0;
        }
    }
    while(n){
        if(n%2){
            t=t*a;
        }
        n/=2;
        a=a*a;
    }
    return t;
}
int main(void){
    int t;
    scanf("%d",&t);
    ll n,a,b;
    Mat k;
    memset(k.m,0,sizeof(k.m));
    k.m[0][0]=k.m[0][1]=k.m[2][0]=k.m[2][2]=k.m[3][3]=k.m[4][4]=k.m[5][5]=k.m[6][0]=k.m[6][2]=k.m[6][3]=k.m[6][4]=k.m[6][5]=k.m[6][6]=1;
    k.m[1][0]=k.m[5][4]=2;
    k.m[4][3]=k.m[5][3]=3;
    k.m[3][0]=k.m[3][2]=k.m[5][0]=k.m[5][2]=4;
    k.m[4][0]=k.m[4][2]=6;
    Mat g;
    while(t--){
        scanf("%lld%lld%lld",&n,&a,&b);
        if(n==1){
            printf("%lld\n",a%MOD);
        }
        else if(n==2){
            printf("%lld\n",b%MOD);
        }
        else{
            memset(g.m,0,sizeof(g));
            g.m[0][0]=b;
            g.m[0][1]=a;
            g.m[0][2]=16;
            g.m[0][3]=8;
            g.m[0][4]=4;
            g.m[0][5]=2;
            g.m[0][6]=1;
            printf("%lld\n",(g*(k^(n-2))).m[0][0]%MOD);
        }
    }
    return 0;
}